package com.lxu.gc;

public class TestThreadLocalGC {

    private static ThreadLocal<String> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
            tl.set("123");
            String s = tl.get();
            System.out.println(Thread.currentThread().getName() + "-w-666before GC -----" + s);
            tl.remove();
            System.gc();
            System.out.println(Thread.currentThread().getName() + "-w-a666fter GC -----" + tl.get());
            try {
                Thread.sleep(1000000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "--after GC -----" + tl.get());
        }).start();
    }
}
